package com.changli07._interface;

public class USBTest {
    public static void main(String[] args) {
        Computer c1 = new Computer();
        Printer p1 = new Printer();
        //多态性的体现
//        1.接口实现类的对象
        c1.transferData(p1);
//        2.接口实现类的匿名对象
        c1.transferData(new Camera());
//        3.接口匿名实现类的对象
        USB usb = new USB(){
            public void start() {
                System.out.println("U盘已插入");
            }
            public void stop(){
                System.out.println("U盘已拔出");
            }
        };
        c1.transferData(usb);
//        4.接口匿名实现类的匿名对象
        c1.transferData(new USB(){
            public void start() {
                System.out.println("扫描仪 开始工作了");
            }
            public void stop() {
                System.out.println("扫描仪结束工作了");
            }
        });
    }
}
class Computer {
    public void transferData(USB usb){//USB usb = new Printer();
        System.out.println("usb连接成功......");
        usb.start();
        System.out.println("usb传输中......");
        usb.stop();
    }
}
class Camera implements USB{

    @Override
    public void start() {
        System.out.println("照相机开始工作！！！");
    }

    @Override
    public void stop() {
        System.out.println("照相机结束工作！！！");
    }
}
class Printer implements USB{
    public void start(){
        System.out.println("开始准备打印!!!");
    }
    public void stop(){
        System.out.println("打印完成!!!");
    }
}
interface USB{
    //USB的长宽属性
    public static final int length = 5;
    int width = 1;

    //USB的方法
    public abstract  void start();
    void stop();

}
